<?php
/**
 * Created by PhpStorm.
 * User: chenlingguang
 * Date: 2018/3/27
 * Time: 上午11:31
 */

namespace App\Utils;

class Curl {


    public static function sendGetRequest($header, $url) {
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_HTTPGET, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        if($header != null)
            curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        $response = curl_exec($curl);
        curl_close($curl);
        return $response;
    }

    public static function sendPostRequest($header, $data, $url)
    {
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        if($header != null) {
            curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        }
        $response = curl_exec($curl);

        curl_close($curl);
        return $response;
    }
}